package com.kaka.bus.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kaka.bus.R;
import com.kaka.bus.bean.MoneyRecordBean;
import com.kaka.bus.util.U;

import java.util.List;

/**
 * Created by zhangqi on 2017/12/25.
 * e-mail : ${email}
 * desc :
 */

public class RecordAdapter extends BaseQuickAdapter<MoneyRecordBean,BaseViewHolder> {

    public RecordAdapter(int layoutResId, @Nullable List<MoneyRecordBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MoneyRecordBean item) {
        int position = helper.getAdapterPosition();
        if(position % 2 == 1){
            helper.itemView.setBackgroundColor(Color.parseColor("#e8e8e8"));
        }else{
            helper.itemView.setBackgroundResource(R.drawable.message_ripple_gray);
        }
        String moneyT = U.convert(Double.parseDouble(item.getAmount())) + "";
        if(moneyT.endsWith(".0") || moneyT.endsWith(".1") || moneyT.endsWith(".2") || moneyT.endsWith(".3")
                || moneyT.endsWith(".4") || moneyT.endsWith(".5") || moneyT.endsWith(".6") || moneyT.endsWith(".7")
                || moneyT.endsWith(".8") || moneyT.endsWith(".9")){
            moneyT = moneyT+"0";
        }
        helper.setText(R.id.tv_item_type,item.getOperationTypeName())
                .setText(R.id.tv_item_money,moneyT)
                .setText(R.id.tv_item_time,item.getAddDateTime());
    }
}
